package com.dingreading.cloud.soms.controller;

import com.dingreading.cloud.common.base.R;
import com.dingreading.cloud.soms.entity.Stores;
import com.dingreading.cloud.soms.service.StoresService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/front/store")
@Api(tags = "门店-门店信息管理")
public class FrontStoreController {

    @Resource
    private StoresService storesService;

    @ApiOperation(value = "获取公司下的门店信息")
    @PostMapping(value = "/getCorpStores", produces = "application/json; charset=UTF-8")
    public R<Object> getCorpStores(
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid
    ) {
        Stores stores = storesService.getByUid(storeUid);
        if (null == stores)
            return R.fail("门店获取失败");

        List<Stores> list = storesService.getByCorpUidAndEnabled(stores.getCorpUid());

        return R.ok(list);
    }

    @ApiOperation(value = "获取公司下的其他门店")
    @PostMapping(value = "/getCorpOtherStores", produces = "application/json; charset=UTF-8")
    public R<Object> getCorpOtherStores(
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "员工uid") @RequestParam(value = "staffUid") String staffUid,
            @ApiParam(value = "员工姓名") @RequestParam(value = "staffName") String staffName,
            @ApiParam(value = "公司uid") @RequestParam(value = "corpUid") String corpUid
    ) {
        List<Stores> list = storesService.getCorpOtherStores(corpUid, storeUid);

        return R.ok(list);
    }

}